<?php
class PublicAction extends CommonAction {
	//后台登录页面
	public function index(){
		$this->display();	
	}
	
	//验证码
	public function verify(){
    	import('ORG.Util.Image');
    	Image::buildImageVerify();
	}
	
	//验证登录
	public function login(){
		//判断验证码是否正确
		$verify_code = $_POST["verify_code"];
		if($_SESSION['verify'] != md5($verify_code)) {
			$this->error('验证码错误！','index');
		}else{
			// 实例化Admin对象
			$Admin = M("Admin"); 
			$user_name = $_POST["user_name"];
			$password = $_POST["password"];	
			$row = $Admin->where("user_name = '".$user_name."' and password = '".md5($password)."'")->find();
			//echo $Admin->getLastSql();exit;
			if($row){
				//登录成功，记录相关session
				session(C('USER_AUTH_KEY'),$row["id"]);
				session('USER_NAME',$row["user_name"]);
				$this->redirect('Index/index');
			}else{
				//用户名或密码错误	
				$this->error('用户名或密码错误！','index');
			}
		}
	}
	
	//退出登录
	public function loginOut(){
		//清空所有session
		session(NULL);
		$this->redirect('Public/index');	
	}
	
	
}

?>